import { defineStore } from 'pinia';
import type { ThemeSetting, ThemeLayoutMode, ThemeAnimateMode } from '@/interface';
import { defaultThemeSetting } from './themeHelper';

type ThemeState = ThemeSetting;

export const useThemeStore = defineStore('theme-store', {
    state: (): ThemeState => defaultThemeSetting,
    getters: {},
    actions: {
        /** 重置theme状态 */
        resetThemeStore() {
            this.$reset();
        },
        /** 设置布局最小宽度 */
        setLayoutMinWidth(minWidth: number) {
            this.layout.minWidth = minWidth;
        },
        /** 设置布局模式 */
        setLayoutMode(mode: ThemeLayoutMode) {
            this.layout.mode = mode;
        },

        /** 设置头部高度 */
        setHeaderHeight(height: number | null) {
            if (height) {
                this.header.height = height;
            }
        },

        /** 侧边栏宽度 */
        setSiderWidth(width: number | null) {
            if (width) {
                this.sider.width = width;
            }
        },
        /** 侧边栏折叠时的宽度 */
        setSiderCollapsedWidth(width: number) {
            this.sider.collapsedWidth = width;
        },
        /** vertical-mix模式下侧边栏宽度 */
        setMixSiderWidth(width: number | null) {
            if (width) {
                this.sider.mixWidth = width;
            }
        },
        /** vertical-mix模式下侧边栏折叠时的宽度 */
        setMixSiderCollapsedWidth(width: number) {
            this.sider.mixCollapsedWidth = width;
        },
        /** vertical-mix模式下侧边栏展示子菜单的宽度 */
        setMixSiderChildMenuWidth(width: number) {
            this.sider.mixChildMenuWidth = width;
        },
        /** 设置底部是否固定 */
        setFooterIsFixed(isFixed: boolean) {
            this.footer.fixed = isFixed;
        },
        /** 设置底部高度 */
        setFooterHeight(height: number) {
            this.footer.height = height;
        },
        /** 设置切换页面时是否过渡动画 */
        setPageIsAnimate(animate: boolean) {
            this.page.animate = animate;
        },
        /** 设置页面过渡动画类型 */
        setPageAnimateMode(mode: ThemeAnimateMode) {
            this.page.animateMode = mode;
        }
    }
});
